import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DiscountsInfoVO, DiscountsInfoForm, DiscountsInfoQuery } from '@/api/system/discountsInfo/types';
import { DiscountsCdkLogForm } from '@/api/system/discountsCdkLog/types';

/**
 * 查询优惠券信息列表
 * @param query
 * @returns {*}
 */

export const listDiscountsInfo = (query?: DiscountsInfoQuery): AxiosPromise<DiscountsInfoVO[]> => {
  return request({
    url: '/system/discounts/queryDiscountsPageList',
    method: 'get',
    params: query
  });
};

/**
 * 新增优惠券信息
 * @param data
 */
export const addDiscountsInfo = (data: DiscountsInfoForm) => {
  return request({
    url: '/system/discounts/createDiscounts',
    method: 'post',
    data: data
  });
};

/**
 * 优惠券作废
 */
export const discountsInfoDisabled = (data: DiscountsCdkLogForm) => {
  return request({
    url: '/system/discounts/discountsInfoDisabled',
    method: 'post',
    data: data
  });
};

/**
 * 查询店铺正在进行中的拼团
 */
export const queryShopStartCollageList = () => {
  return request({
    url: '/system/discounts/queryShopStartCollageList',
    method: 'get'
  });
};

/**
 * 查询优惠券详情
 */
export const getDiscountsInfoById = (discountsId: number) => {
  return request({
    url: '/system/discounts/getDiscountsInfoById',
    method: 'get',
    params: { discountsId: discountsId }
  });
};

/**
 * 赠送优惠券
 */
export const giveDiscounts = (data: any) => {
  return request({
    url: '/system/discounts/giveDiscounts',
    method: 'post',
    data: data
  });
};
